package com.example.demo.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.Result;
import com.example.demo.entity.User;
import com.example.demo.entity.WebPage1User;
import com.example.demo.mapper.WebPage1UserMapper;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/webpage1")
//碰到user
public class Page1Controller {
    @Resource
    WebPage1UserMapper webPage1UserMapper;

    @PostMapping
    public Result<?> save(@RequestBody WebPage1User webPage1User){
        if(webPage1User.getName()==null){
        webPage1User.setName("zhu");
        webPage1User.setMessage("zhu");
        }
        webPage1UserMapper.insert(webPage1User);
        return Result.success();
    }
    @PutMapping
    public Result<?> update(@RequestBody WebPage1User webPage1User){
        webPage1UserMapper.updateById(webPage1User);
        return Result.success();
    }
    @GetMapping
    public List<WebPage1User> selectList(@RequestParam int searchId,@RequestParam int searchPageId,@RequestParam int kindId){
        LambdaQueryWrapper<WebPage1User>wrapper= Wrappers.<WebPage1User>lambdaQuery();
        wrapper.eq(WebPage1User::getBlockId,searchId);
        wrapper.eq(WebPage1User::getPageId,searchPageId);
        wrapper.eq(WebPage1User::getKindId,kindId);
        return webPage1UserMapper.selectList(wrapper);
    }
    @DeleteMapping("/deletebyId/{id}")
    public Result<?> update1 (@PathVariable Long id){
        webPage1UserMapper.deleteById(id);
        return Result.success();
    }
    @DeleteMapping("/deletebyblockId/{blockId}")
    public Result<?> update2 (@PathVariable Long blockId){
        LambdaQueryWrapper<WebPage1User>wrapper= Wrappers.<WebPage1User>lambdaQuery();
        wrapper.eq(WebPage1User::getBlockId,blockId);
        webPage1UserMapper.delete(wrapper);
        return Result.success();
    }
}
